package com.apes.fn.scm.purchaseReturn.model;

import com.apes.framework.jpa.BaseModel;
import com.apes.framework.jpa.DefaultPersistListener;
import com.apes.framework.jpa.comment.Comment;
import com.apes.framework.jpa.generator.ApesGenerator;
import com.apes.framework.util.ApesConst;
import com.apes.scm.account.account.model.InventoryBatch;
import com.apes.scm.masterdata.party.model.PartyRole;
import com.apes.scm.masterdata.product.model.Product;
import com.apes.scm.masterdata.product.model.ProductUom;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.SelectBeforeUpdate;

import javax.persistence.*;
import javax.validation.constraints.NotNull;

/**
 * @ClassName PurchaseReturnApplyItem
 * @Description 返厂申审批单明细
 * @Author pengyb
 * @Date 2020/1/19 15:06
 * @Version 1.0
 **/
@Getter
@Setter
@SelectBeforeUpdate
@DynamicInsert
@DynamicUpdate
@Entity
@EntityListeners(DefaultPersistListener.class)
@Table(name = PurchaseReturnApprovalItem.CONST_TABLE_NAME)
public class PurchaseReturnApprovalItem extends BaseModel {
    public static final String CONST_TABLE_NAME = "purchase_return_approval_item";
    @Id
    @Column(name = "id")
    @ApesGenerator(code = CONST_TABLE_NAME, name = "返厂审批单明细")
    @Comment("唯一编码")
    private long id;

    @NotNull
    @ManyToOne(optional = false)
    @JoinColumn(name = "return_id", referencedColumnName = "id")
    @Comment("返厂审批单号")
    private PurchaseReturnApproval purchaseReturnApproval;


    @NotNull
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "product_id", referencedColumnName = "id")
    @Comment("商品")
    private Product product;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "supplier_id", referencedColumnName = "id")
    @Comment("供应商")
    private PartyRole supplier;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "barch_code", referencedColumnName = "id")
    @Comment("商品批次内码")
    private InventoryBatch inventoryBatch;

    @NotNull
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "product_uom_id", referencedColumnName = "id")
    @Comment("计量单位")
    private ProductUom uom;

    @Column(name = "price_unit", nullable = false, columnDefinition = ApesConst.FIELD_MONEY_16_4_0)
    @Comment("单价")
    private double priceUnit = 0;

    @Column(name = "product_sum_qty", nullable = false, columnDefinition = ApesConst.FIELD_QTY_16_4_0)
    @Comment("商品总数（可退数量）")
    private double productSumQty = 0;

    @Column(name = "price_total", nullable = false, columnDefinition = ApesConst.FIELD_MONEY_16_4_0)
    @Comment("总计")
    private double priceTotal = 0;

    @Column(name = "product_return_qty", nullable = false, columnDefinition = ApesConst.FIELD_QTY_16_4_0)
    @Comment("返厂数量")
    private double productReturnQty = 0;

    @Column(name = "product_return_qty_approve", nullable = false, columnDefinition = ApesConst.FIELD_QTY_16_4_0)
    @Comment("同意返厂数量")
    private double productReturnQtyApprove = 0;

    @Column(name = "note")
    @Comment("备注")
    private String note;

    @Column(name = "purchase_return_id")
    @Comment("返厂单号")
    private String purchaseReturnId;
}
